package com.archgeek.bigdata;

import org.apache.commons.lang.math.RandomUtils;
import org.joda.time.DateTime;

import java.io.IOException;
import java.sql.Connection;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

/**
 * java -cp code-hive-1.0.0-SNAPSHOT.jar com.archgeek.bigdata.KyuubiTest
 *
 * @author pizhihui
 * @date 2022-03-12
 */
public class KyuubiTest {

    private static String KYUUBI_URL = "jdbc:hive2://10.10.16.165:2181/default;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=kyuubi_test";    //填写hive的IP，之前在配置文件中配置的IP


    public static void main(String[] args) throws IOException {

        Properties property = FileUtils.get();
        int threadNum = Integer.parseInt(property.getProperty("kyuubi.thread.num"));
        int singleNum = Integer.parseInt(property.getProperty("kyuubi.thread.single.num"));

        System.out.println("开始执行SQL......");

        Runnable r = () -> {
            String sql = "\n" +
                    "select a.fuid,\n" +
                    "       b.fuid as fuid0\n" +
                    "from\n" +
                    "        (select distinct fuid\n" +
                    "        FROM  dp_xykj_mart.level_riskmatch_plus_features\n" +
                    "        WHERE F_P_DATE='2022-03-01' and   FRISK_MATCH=1 ) a\n" +
                    "left join\n" +
                    "        (select distinct fuid from dp_xykj_mart.letupro_black_list_s_d where f_p_date='2022-03-01' and risk_match=1) b\n" +
                    "on a.fuid=b.fuid\n" +
                    "where b.fuid is null limit 100";
            HiveTool.getSql(KYUUBI_URL, sql);
        };

        Runnable r2 = () -> {
            RandomUtils.nextInt(5);
            System.out.println(DateTime.now() + ":::执行了");
        };

        TlUtil.timeTasks(threadNum, singleNum, r2);
        System.out.println("结束.....");


    }


}
